package com.nuotu.datawall.clouddata.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.nuotu.datawall.clouddata.R;
import com.nuotu.datawall.clouddata.been.BorrowCount;
import com.nuotu.datawall.clouddata.util.XUtilsImage;

import org.xutils.x;

import java.util.ArrayList;

public class SpecialAdapter extends ArrayAdapter {

    private Context mContext;
    private int layoutResourceId;
    private ArrayList<BorrowCount> mGridData;
    public SpecialAdapter(Context context, int resource, ArrayList<BorrowCount> objects) {
        super(context, resource, objects);
        this.mContext = context;
        this.layoutResourceId = resource;
        this.mGridData = objects;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.borrowCount_bookName = (TextView) convertView.findViewById(R.id.borrowCount_bookName);
            holder.borrowCount_bookAuthor = (TextView) convertView.findViewById(R.id.borrowCount_bookAuthor);
            holder.borrowCount_bookFile = (ImageView) convertView.findViewById(R.id.borrowCount_bookFile);
            holder.borrowCount_borrowCount = (TextView) convertView.findViewById(R.id.borrowCount_borrowCount);
            holder.borrowCount_xh = (Button) convertView.findViewById(R.id.borrowCount_xh);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BorrowCount item = mGridData.get(position);
        holder.borrowCount_bookName.setText(item.getBookName());
        holder.borrowCount_bookAuthor.setText("作者:"+item.getBookAuthor());
        holder.borrowCount_borrowCount.setVisibility(View.GONE);
        holder.borrowCount_xh.setVisibility(View.GONE);
        x.image().bind(holder.borrowCount_bookFile,item.getFileUrl(), XUtilsImage.getInstance().getImageOptions());
        return convertView;
    }
    private class ViewHolder {
        public TextView borrowCount_bookName;
        public TextView borrowCount_bookAuthor;
        public ImageView borrowCount_bookFile;
        public TextView borrowCount_borrowCount;
        public Button borrowCount_xh;
    }
}